QuickOPC User's Guide and Reference
ReadMultipleItemValues(IEasyDAClient,ServerDescriptor,DAItemDescriptor[]) Method
Example 



OpcLabs.EasyOpcClassic Assembly > OpcLabs.EasyOpc.DataAccess Namespace > IEasyDAClientExtension Class > ReadMultipleItemValues Method : ReadMultipleItemValues(IEasyDAClient,ServerDescriptor,DAItemDescriptor[]) Method
The client object that will perform the operation.
The OPC server involved in the operation.
Array of OPC items involved in the operation.
Reads named items from an OPC server or OPC servers. Only the item values are returned (qualities and timestamps are not returned). Reads multiple named item values from a single OPC server, using descriptor objects for the OPC server and OPC-DA items.
Syntax
'Declaration
 
<ExtensionAttribute()>
<ElementsNotNullAttribute()>
<NotNullAttribute()>
Public Overloads Shared Function ReadMultipleItemValues( _
   ByVal client As IEasyDAClient, _
   ByVal serverDescriptor As ServerDescriptor, _
   ByVal itemDescriptorArray() As DAItemDescriptor _
) As ValueResult()
'Usage
 
Dim client As IEasyDAClient
Dim serverDescriptor As ServerDescriptor
Dim itemDescriptorArray() As DAItemDescriptor
Dim value() As ValueResult
 
value = IEasyDAClientExtension.ReadMultipleItemValues(client, serverDescriptor, itemDescriptorArray)
[Extension()]
[ElementsNotNull()]
[NotNull()]
public static ValueResult[] ReadMultipleItemValues( 
   IEasyDAClient client,
   ServerDescriptor serverDescriptor,
   DAItemDescriptor[] itemDescriptorArray
)
[Extension()]
[ElementsNotNull()]
[NotNull()]
public:
static array<ValueResult^>^ ReadMultipleItemValues( 
   IEasyDAClient^ client,
   ServerDescriptor^ serverDescriptor,
   array<DAItemDescriptor^>^ itemDescriptorArray
) 

Parameters

client
The client object that will perform the operation.
serverDescriptor
The OPC server involved in the operation.
itemDescriptorArray
Array of OPC items involved in the operation.

Return Value

The function returns an array of OpcLabs.BaseLib.OperationModel.ValueResult objects. The indices of elements in the output array are the same as those in the input array, itemDescriptorArray.
Exceptions
ExceptionDescription
A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.
Remarks

The servers can be local or can be remotely accessed via DCOM. Optionally, an access path can be specified or a specific data type can be requested.

The ReadMultipleItemValues method requires that the quality is "good" for each item. The function performs all individual operations in parallel, but only returns after all individual operations are completed (or their timeouts elapse).

This method does not throw an exception in case of OPC operation failures. Instead, the eventual exception related to each item is returned in Exception property of each returned OpcLabs.EasyOpc.DataAccess.OperationModel.DAVtqResult element.

The size of the input array will become the size of the output array. The element positions (indices) in the output array are the same as in the input array.

 

This is a multiple-operation method. In a properly written program, it does not throw any exceptions. You should therefore not put try/catch statements or similar constructs around calls to this method. The only exceptions thrown by this method are for usage errors, i.e. when your code violates the usage contract of the method, such as passing in invalid arguments or calling the method when the state of the object does not allow it. Any operation-related errors (i.e. errors that depend on external conditions that your code cannot reliably check) are indicated in the result objects returned by the method. For more information, see Multiple-operation Methods and Do not catch any exceptions with asynchronous or multiple-operation methods.
Example
// This example shows how to read values of 4 items at once, and display them.

using System;
using System.Diagnostics;
using OpcLabs.BaseLib.OperationModel;
using OpcLabs.EasyOpc.DataAccess;

namespace DocExamples.DataAccess._EasyDAClient
{
    class ReadMultipleItemValues
    {
        public static void Main1()
        {
            // Instantiate the client object.
            var client = new EasyDAClient();

            ValueResult[] valueResults = client.ReadMultipleItemValues("OPCLabs.KitServer.2",
                new DAItemDescriptor[]
                {
                    "Simulation.Random", "Trends.Ramp (1 min)", "Trends.Sine (1 min)", "Simulation.Register_I4"
                });

            for (int i = 0; i < valueResults.Length; i++)
            {
                ValueResult valueResult = valueResults[i];
                Debug.Assert(!(valueResult is null));

                if (valueResult.Succeeded)
                    Console.WriteLine($"valueResults({i}).Value: {valueResult.Value}");
                else
                    Console.WriteLine($"valueResults({i}) *** Failure: {valueResult.ErrorMessageBrief}");
            }
        }


        // Example output:
        //
        //valueResults(0).Value: 0.00125125888851588
        //valueResults(1).Value: 0.732510924339294
        //valueResults(2).Value: -0.993968485238202
        //valueResults(3).Value: 0
    }
}
# This example shows how to read values of 4 items at once, and display them.

#requires -Version 5.1
using namespace OpcLabs.EasyOpc.DataAccess

# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Assemblies/net47/OpcLabs.EasyOpcClassic.dll"

# Instantiate the client object.
$client = New-Object EasyDAClient

$valueResults = [IEasyDAClientExtension]::ReadMultipleItemValues($client, 
    "OPCLabs.KitServer.2", @(
        (New-Object DAItemDescriptor("Simulation.Random")),
        (New-Object DAItemDescriptor("Trends.Ramp (1 min)")),
        (New-Object DAItemDescriptor("Trends.Sine (1 min)")),
        (New-Object DAItemDescriptor("Simulation.Register_I4"))
        ))

for ($i = 0; $i -lt $valueResults.Length; $i++) {
    $valueResult = $valueResults[$i]
    if ($valueResult.Succeeded) {
        Write-Host "valueResults($($i)).Value: $($valueResult.Value)"
    }
    else {
        Write-Host "valueResults($($i)) *** Failure: $($valueResult.ErrorMessageBrief)"
    }
}


# Example output:
#
#valueResults(0).Value: 0.00125125888851588
#valueResults(1).Value: 0.732510924339294
#valueResults(2).Value: -0.993968485238202
#valueResults(3).Value: 0
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2012, Windows Server 2016; .NET Core, .NET 5, .NET 6: Linux, macOS, Microsoft Windows

See Also

Reference

IEasyDAClientExtension Class
IEasyDAClientExtension Members
Overload List